import { Module } from 'vuex';
import { Session } from '/@/utils/storage';
// 此处加上 `.ts` 后缀报错，具体原因不详
import { HardwareConfigState, RootStateTypes } from '/@/store/interface/index';
import { stat } from 'fs';

const hardwareModule: Module<HardwareConfigState, RootStateTypes> = {
	namespaced: true,
	state: {
		hardwareConfigRows: [],
	},
	mutations: {
		// 设置用户信息
		setHardwareConfig(state: any, data: Array<object>) {
			state.hardwareConfigRows = data;
		},
	},
	actions: {
		// 设置用户信息
		async setHardwareConfig({ commit }, data: Array<object>) {
			if (data) {
				commit('setHardwareConfig', data);
			}
		},
		async getHardwareConfig({ commit, state }) {
			return state.hardwareConfigRows;
		},
		async getHardwareConfigByKey({ state }, key) {
			var rows = state.hardwareConfigRows;
			for (var i = 0; i < rows.length; i++) {
				var r = rows[i];
				if (r.code == key) {
					return r;
				}
			}
			return null;
		},
	},
};

export default hardwareModule;
